package Exams.exam;

import java.util.HashMap;

public class Q1 {
    public static void main(String[] args) {
        int[] A = new int[]{1,2};
        System.out.println(solution(A));
    }

    public static int solution(int[] A){

        HashMap<Integer,Integer> counts=new HashMap<>();
        for (int c : A) {
            if (counts.containsKey(c)) {
                Integer val = counts.get(c);
                val++;
                counts.put(c, val);
            } else {
                counts.put(c, 1);
            }
        }
        int res = 0;
        int value;

        for(Integer key:counts.keySet()){
            value=counts.get(key);
            if (value == key ) {
                continue;
            }

            if (value > key){
                res += value - key;
            }else if(value > key/2){
                res += (key - value);
            }else if (value <= key/2){
                res += value;
            }

        }

        return res;
    }
}
